home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / planner / path / hashutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.3 KB  |  170 lines

  1.  
  2. /*     
  3.  *      FILE
  4.  *         hashutils
  5.  *     
  6.  *      DESCRIPTION
  7.  *         Utilities for finding applicable merge clauses and pathkeys
  8.  *     
  9.  */
  10. /* RcsId ("$Header: /private/postgres/src/planner/path/RCS/hashutils.c,v 1.15 1992/07/12 10:57:31 joey Exp $"); */
  11.  
  12. /*     
  13.  *      EXPORTS
  14.  *             group-clauses-by-hashop
  15.  *             match-hashop-hashinfo
  16.  */
  17.  
  18. #include "nodes/pg_lisp.h"
  19. #include "nodes/relation.h"
  20. #include "nodes/relation.a.h"
  21.  
  22. #include "planner/internal.h"
  23. #include "planner/hashutils.h"
  24. #include "planner/clauses.h"
  25.  
  26. /*    
  27.  *        group-clauses-by-hashop
  28.  *    
  29.  *        If a join clause node in 'clauseinfo-list' is hashjoinable, store
  30.  *        it within a hashinfo node containing other clause nodes with the same
  31.  *        hash operator.
  32.  *    
  33.  *        'clauseinfo-list' is the list of clauseinfo nodes
  34.  *        'inner-relid' is the relid of the inner join relation
  35.  *    
  36.  *        Returns the new list of hashinfo nodes.
  37.  *    
  38.  */
  39.  
  40. /*  .. find-all-join-paths */
  41.  
  42. LispValue
  43. group_clauses_by_hashop (clauseinfo_list,inner_relid)
  44.      LispValue clauseinfo_list,inner_relid ;
  45. {
  46.     LispValue hashinfo_list = LispNil;
  47.     CInfo clauseinfo = (CInfo)NULL;
  48.     LispValue i = LispNil;
  49.     LispValue temp = LispNil;
  50.     LispValue temp2 = LispNil;
  51.     ObjectId hashjoinop = 0;
  52.     
  53.     foreach (i,clauseinfo_list) {
  54.     clauseinfo = (CInfo)CAR(i);
  55.     hashjoinop = get_hashjoinoperator(clauseinfo);
  56.     
  57.     /*    Create a new hashinfo node and add it to */
  58.     /*    'hashinfo-list' if one does not yet */
  59.     /*    exist for this hash operator.   */
  60.     
  61.     if (hashjoinop ) {
  62.         HInfo xhashinfo = (HInfo)NULL;
  63.         LispValue clause = get_clause (clauseinfo);
  64.         Var leftop = get_leftop(clause);
  65.         Var rightop = get_rightop(clause);
  66.         JoinKey keys = (JoinKey)NULL;
  67.         
  68.         xhashinfo = 
  69.           match_hashop_hashinfo (hashjoinop,hashinfo_list);
  70.         
  71.         if (CInteger(inner_relid) == get_varno (leftop)){
  72.         keys = MakeJoinKey((LispValue)rightop,
  73.                    (LispValue)leftop);
  74.         }
  75.         else {
  76.         keys = MakeJoinKey((LispValue)leftop,
  77.                    (LispValue)rightop);
  78.         }
  79.         
  80.         if ( null(xhashinfo)) {
  81.         xhashinfo = RMakeHInfo();
  82.         set_hashop(xhashinfo,
  83.                hashjoinop);
  84.  
  85.         set_jmkeys((JoinMethod)xhashinfo,LispNil);
  86.         set_clauses((JoinMethod)xhashinfo,LispNil);
  87.  
  88. /*        set_clause(xhashinfo,NULL);
  89.         set_selectivity(xhashinfo,0);
  90.         set_notclause(xhashinfo,false);
  91.         set_indexids(xhashinfo,LispNil);
  92.         set_mergesortorder(xhashinfo,(MergeOrder)NULL);
  93.  */
  94.  
  95.         /* XXX was push  */
  96.         hashinfo_list = nappend1(hashinfo_list,(LispValue)xhashinfo);
  97.         hashinfo_list = nreverse(hashinfo_list);
  98.         }
  99.  
  100.         /* XXX was "push" function  */
  101.         /* push (clause,joinmethod_clauses (xhashinfo));
  102.          *  push (keys,joinmethod_keys (xhashinfo));
  103.          */
  104.         
  105.         if (null(get_clauses((JoinMethod)xhashinfo)))
  106.         {
  107.           set_clauses((JoinMethod)xhashinfo,lispCons((LispValue)clause, LispNil));
  108.         }
  109.         else {
  110.         temp = lispList();
  111.         CAR(temp) = CAR(get_clauses((JoinMethod)xhashinfo));
  112.         CDR(temp) = CDR(get_clauses((JoinMethod)xhashinfo));
  113.         CDR(get_clauses((JoinMethod)xhashinfo)) = temp;
  114.         CAR(get_clauses((JoinMethod)xhashinfo)) = clause;
  115.         }
  116.         if (null(get_jmkeys((JoinMethod)xhashinfo)))
  117.         {
  118.           set_jmkeys((JoinMethod)xhashinfo,lispCons((LispValue)keys, LispNil));
  119.         }
  120.         else {
  121.         temp2 = lispList();
  122.         
  123.         CAR(temp2) = CAR(get_jmkeys((JoinMethod)xhashinfo));
  124.         CDR(temp2) = CDR(get_jmkeys((JoinMethod)xhashinfo));
  125.         CDR(get_jmkeys((JoinMethod)xhashinfo)) = temp2;
  126.         CAR(get_jmkeys((JoinMethod)xhashinfo)) = (LispValue)keys;
  127.         }
  128.  
  129. /*        temp2 = get_jmkeys(xhashinfo);
  130.         temp2 = nappend1(temp2,keys);
  131.         temp2 = nreverse(temp2);
  132.  */        
  133.     }
  134.     }
  135.     return(hashinfo_list);
  136. } /* function end */
  137.  
  138.  
  139. /*    
  140.  *        match-hashop-hashinfo
  141.  *    
  142.  *        Searches the list 'hashinfo-list' for a hashinfo node whose hash op
  143.  *        field equals 'hashop'.
  144.  *    
  145.  *        Returns the node if it exists.
  146.  *    
  147.  */
  148.  
  149. /*  .. group-clauses-by-hashop */
  150.  
  151. HInfo
  152. match_hashop_hashinfo (hashop,hashinfo_list)
  153.      LispValue hashinfo_list ;
  154.      ObjectId hashop;
  155. {
  156.     ObjectId key = 0;
  157.     HInfo xhashinfo = (HInfo)NULL;
  158.     LispValue i = LispNil;
  159.     
  160.     /* XXX -- Lisp find and lambda function --- maybe wrong */
  161.     foreach( i, hashinfo_list) {
  162.     xhashinfo = (HInfo)CAR(i);
  163.     key = get_hashop(xhashinfo);
  164.     if (hashop == key) {  /* found */
  165.         return(xhashinfo);    /* should be a hashinfo node ! */
  166.     }
  167.     }
  168.     return((HInfo)LispNil);
  169. }
  170.